package com.ding.servlet;

import com.alibaba.fastjson.JSON;
import com.ding.entity.Class;
import com.ding.service.ClassService;
import com.ding.service.Impl.ClassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ClassServlet",urlPatterns = "/class.action")
public class ClassServlet extends HttpServlet {
    ClassService classService = new ClassServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String opr = (request.getParameter("opr")==null||"".equals(request.getParameter("opr")))
                ?"list":request.getParameter("opr");

        switch (opr){
            case "list":
                List<Class> classList = classService.selectAll();
                String json = JSON.toJSONString(classList);
                response.getWriter().print(json);
                return;
            case "add":

                return;
            case "update":

                return;
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
